﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ASCalpuff.FileLayers
{
    public class MG3 : Group
    {
        // Fields


        /// <summary>
        /// 是否保存网格风场为外部文件，CALMET.DAT          
        /// </summary>
        private bool m_LSAVE = true;

        /// <summary>
        /// 风场输出类型，  1 = CALPUFF/CALGRID type file (CALMET.DAT)
        /// 2 = MESOPUFF-II type file     (PACOUT.DAT)
        /// </summary>
        private int m_IFORMO = 1;



        //列表文件CALMET.LST输出控制  LINE PRINTER OUTPUT OPTIONS:

        /// <summary>
        /// 打印输出变量，如果=T，则会在在CALMET.LST中输出网格风场，建议False       
        /// </summary>
        private bool m_LPRINT = true;


        //CALMET.LST控制输出 LINE PRINTER OUTPUT OPTIONS:

        //以多少小时间隔输出网格风场，默认是1小时，仅当LPRINT=T有作用
        private int m_IPRINF = 1;

        // 控制输出哪个垂向层的u，v风场      
        private List<int> m_IUVOUT = new List<int>();

        //控制输出哪个垂向层的3D温度
        private List<int> m_ITOUT = new List<int>();
        //控制输出哪个垂向层的w风场
        private List<int> m_IWOUT = new List<int>();



        //控制哪个气象参数被输出，默认为0不输出，1为输出
        //稳定度
        private int m_STABILITY = 0;
        //摩擦速度
        private int m_USTAR = 0;
        //莫宁霍夫长度
        private int m_MONIN = 0;

        //混合层高度
        private int m_MIXHT = 0;
        //对流速度尺度
        private int m_WSTAR = 0;
        //降雨量
        private int m_PRECIP = 0;
        //显热通量
        private int m_SENSHEAT = 0;
        //对流混合层高度
        private int m_CONVZI = 0;




        //气象模型的测试和调试打印选项Testing and debug print options for micrometeorological module


        //  打印气象数据在CALMET.LST里，此变量将产生大量的输出      
        private bool m_LDB = false;


        //First time step for which debug data
        // are printed (NN1)                Default: 1       
        private int m_NN1 = 1;

        //Last time step for which debug data
        // are printed (NN2)                Default: 1       
        private int m_NN2 = 2;


        /// <summary>
        /// Print distance to land     internal variables (LDBCST)   
        /// INPUT GROUP: 3 -- Output Options 未找到窗体对应
        /// </summary>
        private bool m_LDBCST = false;




        //风场模型的测试和调试打印选项    输出文件包括TEST.PRT, TEST.OUT,  TEST.KIN, TEST.FRD, and TEST.SLP


        //风场的控制变量输出到文件中， 0=不输出, 1=输出
        private int m_IOUTD = 0;

        //层数, starting at the surface,
        private int m_NZPRN2 = 1;



        //风场分量输出，0不输出，1输出
        private int m_IPR0 = 0;

        //地形调整表面风场
        private int m_IPR1 = 0;


        //风场平滑和初始divergence
        private int m_IPR2 = 0;

        // 测试最终风向和风速
        private int m_IPR3 = 0;

        //最终散度
        private int m_IPR4 = 0;

        //运动学效应调整的风场
        private int m_IPR5 = 0;

        //Froude数调整的风场
        private int m_IPR6 = 0;


        // 坡风调整的风场
        private int m_IPR7 = 0;


        // 最终风场
        private int m_IPR8 = 0;


        // Properties

        #region 属性
        public int CONVZI
        {
            get
            {
                return this.m_CONVZI;
            }
            set
            {
                this.m_CONVZI = value;
            }
        }

        public int IFORMO
        {
            get
            {
                return this.m_IFORMO;
            }
            set
            {
                this.m_IFORMO = value;
            }
        }

        public int IOUTD
        {
            get
            {
                return this.m_IOUTD;
            }
            set
            {
                this.m_IOUTD = value;
            }
        }

        public int IPR1
        {
            get
            {
                return this.m_IPR1;
            }
            set
            {
                this.m_IPR1 = value;
            }
        }

        public int IPR2
        {
            get
            {
                return this.m_IPR2;
            }
            set
            {
                this.m_IPR2 = value;
            }
        }

        public int IPR3
        {
            get
            {
                return this.m_IPR3;
            }
            set
            {
                this.m_IPR3 = value;
            }
        }

        public int IPR4
        {
            get
            {
                return this.m_IPR4;
            }
            set
            {
                this.m_IPR4 = value;
            }
        }

        public int IPR5
        {
            get
            {
                return this.m_IPR5;
            }
            set
            {
                this.m_IPR5 = value;
            }
        }

        public int IPR6
        {
            get
            {
                return this.m_IPR6;
            }
            set
            {
                this.m_IPR6 = value;
            }
        }

        public int IPR7
        {
            get
            {
                return this.m_IPR7;
            }
            set
            {
                this.m_IPR7 = value;
            }
        }

        public int IPR8
        {
            get
            {
                return this.m_IPR8;
            }
            set
            {
                this.m_IPR8 = value;
            }
        }

        public int IPRINF
        {
            get
            {
                return this.m_IPRINF;
            }
            set
            {
                this.m_IPRINF = value;
            }
        }

        public int IPR0
        {
            get
            {
                return this.m_IPR0;
            }
            set
            {
                this.m_IPR0 = value;
            }
        }

        public List<int> ITOUT
        {
            get
            {
                return this.m_ITOUT;
            }
            set
            {
                this.m_ITOUT = value;
            }
        }

        public List<int> IUVOUT
        {
            get
            {
                return this.m_IUVOUT;
            }
            set
            {
                this.m_IUVOUT = value;
            }
        }

        public List<int> IWOUT
        {
            get
            {
                return this.m_IWOUT;
            }
            set
            {
                this.m_IWOUT = value;
            }
        }

        public bool LDB
        {
            get
            {
                return this.m_LDB;
            }
            set
            {
                this.m_LDB = value;
            }
        }

        public bool LDBCST
        {
            get
            {
                return this.m_LDBCST;
            }
            set
            {
                this.m_LDBCST = value;
            }
        }

        public bool LPRINT
        {
            get
            {
                return this.m_LPRINT;
            }
            set
            {
                this.m_LPRINT = value;
            }
        }

        public bool LSAVE
        {
            get
            {
                return this.m_LSAVE;
            }
            set
            {
                this.m_LSAVE = value;
            }
        }

        public int MIXHT
        {
            get
            {
                return this.m_MIXHT;
            }
            set
            {
                this.m_MIXHT = value;
            }
        }

        public int MONIN
        {
            get
            {
                return this.m_MONIN;
            }
            set
            {
                this.m_MONIN = value;
            }
        }

        public int NN1
        {
            get
            {
                return this.m_NN1;
            }
            set
            {
                this.m_NN1 = value;
            }
        }

        public int NN2
        {
            get
            {
                return this.m_NN2;
            }
            set
            {
                this.m_NN2 = value;
            }
        }

        public int NZPRN2
        {
            get
            {
                return this.m_NZPRN2;
            }
            set
            {
                this.m_NZPRN2 = value;
            }
        }

        public int PRECIP
        {
            get
            {
                return this.m_PRECIP;
            }
            set
            {
                this.m_PRECIP = value;
            }
        }

        public int SENSHEAT
        {
            get
            {
                return this.m_SENSHEAT;
            }
            set
            {
                this.m_SENSHEAT = value;
            }
        }

        public int STABILITY
        {
            get
            {
                return this.m_STABILITY;
            }
            set
            {
                this.m_STABILITY = value;
            }
        }

        public int USTAR
        {
            get
            {
                return this.m_USTAR;
            }
            set
            {
                this.m_USTAR = value;
            }
        }

        public int WSTAR
        {
            get
            {
                return this.m_WSTAR;
            }
            set
            {
                this.m_WSTAR = value;
            }
        }


        #endregion



        public override string WriteToGroup()
        {
            string ResultStr = "", TempStr;

            TempStr = "INPUT GROUP: 3 -- Output Options" + "\r\n";
            ResultStr += TempStr;

            TempStr = "DISK OUTPUT OPTION" + "\r\n";
            ResultStr += TempStr;

            if (LSAVE == true)
                TempStr = "! LSAVE = " + "T" + " !" + "\r\n";
            else
                TempStr = "! LSAVE = " + "F" + " !" + "\r\n";
            ResultStr += TempStr;

            TempStr = "! IFORMO = " + IFORMO.ToString() + " !" + "\r\n";
            ResultStr += TempStr;

            TempStr = "LINE PRINTER OUTPUT OPTIONS:" + "\r\n";
            ResultStr += TempStr;

            if (LPRINT == true)
                TempStr = "! LPRINT = " + "T" + " !" + "\r\n";
            else
                TempStr = "! LPRINT = " + "F" + " !" + "\r\n";
            ResultStr += TempStr;

            TempStr = "! IPRINF = " + IPRINF.ToString() + " !" + "\r\n";
            ResultStr += TempStr;

            TempStr = "! IUVOUT = ";
            int j = 0;
            foreach (int i in IUVOUT)
            {
                if (j < IUVOUT.Count - 1)
                    TempStr += i.ToString() + ",  ";
                else
                { TempStr += i.ToString(); }

                j++;
            }

            TempStr += " !" + "\r\n";
            ResultStr += TempStr;


            TempStr = "! IWOUT = ";
            j = 0;
            foreach (int i in IWOUT)
            {
                if (j < IWOUT.Count - 1)
                    TempStr += i.ToString() + ",  ";
                else
                { TempStr += i.ToString(); }

                j++;
            }

            TempStr += " !" + "\r\n";
            ResultStr += TempStr;

            TempStr = "! ITOUT = ";
            j = 0;
            foreach (int i in ITOUT)
            {
                if (j < ITOUT.Count - 1)
                    TempStr += i.ToString() + ",  ";
                else
                { TempStr += i.ToString(); }

                j++;
            }

            TempStr += " !" + "\r\n";
            ResultStr += TempStr;

            TempStr = "! STABILITY = " + STABILITY.ToString() + " !" + "\r\n";
            ResultStr += TempStr;

            TempStr = "! USTAR = " + USTAR.ToString() + " !" + "\r\n";
            ResultStr += TempStr;

            TempStr = "! MONIN = " + MONIN.ToString() + " !" + "\r\n";
            ResultStr += TempStr;

            TempStr = "! MIXHT = " + MIXHT.ToString() + " !" + "\r\n";
            ResultStr += TempStr;

            TempStr = "! WSTAR = " + WSTAR.ToString() + " !" + "\r\n";
            ResultStr += TempStr;

            TempStr = "! PRECIP = " + PRECIP.ToString() + " !" + "\r\n";
            ResultStr += TempStr;

            TempStr = "! SENSHEAT = " + SENSHEAT.ToString() + " !" + "\r\n";
            ResultStr += TempStr;

            TempStr = "! CONVZI = " + CONVZI.ToString() + " !" + "\r\n";
            ResultStr += TempStr;

            TempStr = "Testing and debug print options for micrometeorological module" + "\r\n";
            ResultStr += TempStr;

            if (LDB == true)
                TempStr = "! LDB = " + "T" + " !" + "\r\n";
            else
                TempStr = "! LDB = " + "F" + " !" + "\r\n";
            ResultStr += TempStr;

            TempStr = "First time step for which debug data" + "\r\n";
            ResultStr += TempStr;

            TempStr = "! NN1 = " + NN1.ToString() + " !" + "\r\n";
            ResultStr += TempStr;

            TempStr = "Last time step for which debug data" + "\r\n";
            ResultStr += TempStr;

            TempStr = "! NN2 = " + NN2.ToString() + " !" + "\r\n";
            ResultStr += TempStr;

            if (LDBCST == true)
                TempStr = "! LDBCST = " + "T" + " !" + "\r\n";
            else
                TempStr = "! LDBCST = " + "F" + " !" + "\r\n";
            ResultStr += TempStr;

            TempStr = "! IOUTD  = " + IOUTD.ToString() + " !" + "\r\n";
            ResultStr += TempStr;

            TempStr = "! NZPRN2  = " + NZPRN2.ToString() + " !" + "\r\n";
            ResultStr += TempStr;

            TempStr = "! IPR0  = " + IPR0.ToString() + " !" + "\r\n";
            ResultStr += TempStr;

            TempStr = "! IPR1  = " + IPR1.ToString() + " !" + "\r\n";
            ResultStr += TempStr;

            TempStr = "! IPR2  = " + IPR2.ToString() + " !" + "\r\n";
            ResultStr += TempStr;

            //TempStr = "! IPR1  = " + IPR1.ToString() + " !" + "\r\n";
            //ResultStr += TempStr;

            //TempStr = "! IPR2  = " + IPR2.ToString() + " !" + "\r\n";
            //ResultStr += TempStr;

            TempStr = "! IPR3  = " + IPR3.ToString() + " !" + "\r\n";
            ResultStr += TempStr;

            TempStr = "! IPR4  = " + IPR4.ToString() + " !" + "\r\n";
            ResultStr += TempStr;

            TempStr = "! IPR5  = " + IPR5.ToString() + " !" + "\r\n";
            ResultStr += TempStr;

            TempStr = "! IPR6  = " + IPR6.ToString() + " !" + "\r\n";
            ResultStr += TempStr;

            TempStr = "! IPR7  = " + IPR7.ToString() + " !" + "\r\n";
            ResultStr += TempStr;

            TempStr = "! IPR8  = " + IPR8.ToString() + " !" + "\r\n";
            ResultStr += TempStr;

            TempStr = "! END !" + "\r\n";
            ResultStr += TempStr;

            TempStr = StrWriter.GetCLine();
            ResultStr += TempStr;

            return ResultStr;
        }

        public override void ReadFromGroup(Dictionary<string, string> dic)
        {
            foreach (KeyValuePair<string, string> m_dic in dic)
            {
                if (m_dic.Key == "CONVZI")
                {
                    this.CONVZI = Convert.ToInt32(m_dic.Value);
                }
                if (m_dic.Key == "IFORMO")
                {
                    this.IFORMO = Convert.ToInt32(m_dic.Value);
                }
                if (m_dic.Key == "IOUTD")
                {
                    this.IOUTD = Convert.ToInt32(m_dic.Value);
                }
                if (m_dic.Key == "IPR1")
                {
                    this.IPR1 = Convert.ToInt32(m_dic.Value);
                }
                if (m_dic.Key == "IPR2")
                {
                    this.IPR2 = Convert.ToInt32(m_dic.Value);
                }
                if (m_dic.Key == "IPR3")
                {
                    this.IPR3 = Convert.ToInt32(m_dic.Value);
                }
                if (m_dic.Key == "IPR4")
                {
                    this.IPR4 = Convert.ToInt32(m_dic.Value);
                }
                if (m_dic.Key == "IPR5")
                {
                    this.IPR5 = Convert.ToInt32(m_dic.Value);
                }
                if (m_dic.Key == "IPR6")
                {
                    this.IPR6 = Convert.ToInt32(m_dic.Value);
                }
                if (m_dic.Key == "IPR7")
                {
                    this.IPR7 = Convert.ToInt32(m_dic.Value);
                }
                if (m_dic.Key == "IPR8")
                {
                    this.IPR8 = Convert.ToInt32(m_dic.Value);
                }
                if (m_dic.Key == "IPRINF")
                {
                    this.IPRINF = Convert.ToInt32(m_dic.Value);
                }
                if (m_dic.Key == "IPR0")
                {
                    this.IPR0 = Convert.ToInt32(m_dic.Value);
                }
                if (m_dic.Key == "ITOUT")
                {
                    this.ITOUT = StrWriter.ReturnIntList(m_dic.Value);
                }
                if (m_dic.Key == "IUVOUT")
                {
                    this.IUVOUT = StrWriter.ReturnIntList(m_dic.Value);
                }
                if (m_dic.Key == "IWOUT")
                {
                    this.IWOUT = StrWriter.ReturnIntList(m_dic.Value);
                }
                if (m_dic.Key == "LDB")
                {
                    if (m_dic.Value == "T")
                    {
                        this.LDB = true;
                    }
                    else
                    {
                        this.LDB = false;
                    }

                }
                if (m_dic.Key == "LDBCST")
                {
                    if (m_dic.Value == "T")
                    {
                        this.LDBCST = true;
                    }
                    else
                    {
                        this.LDBCST = false;
                    }
                }
                if (m_dic.Key == "LPRINT")
                {
                    if (m_dic.Value == "T")
                    {
                        this.LPRINT = true;
                    }
                    else
                    {
                        this.LPRINT = false;
                    }
                }
                if (m_dic.Key == "LSAVE")
                {
                    if (m_dic.Value == "T")
                    {
                        this.LSAVE = true;
                    }
                    else
                    {
                        this.LSAVE = false;
                    }
                }
                if (m_dic.Key == "MIXHT")
                {
                    this.MIXHT = Convert.ToInt32(m_dic.Value);
                }
                if (m_dic.Key == "MONIN")
                {
                    this.MONIN = Convert.ToInt32(m_dic.Value);
                }
                if (m_dic.Key == "NN1")
                {
                    this.NN1 = Convert.ToInt32(m_dic.Value);
                }
                if (m_dic.Key == "NN2")
                {
                    this.NN2 = Convert.ToInt32(m_dic.Value);
                }
                if (m_dic.Key == "NZPRN2")
                {
                    this.NZPRN2 = Convert.ToInt32(m_dic.Value);
                }
                if (m_dic.Key == "PRECIP")
                {
                    this.PRECIP = Convert.ToInt32(m_dic.Value);
                }
                if (m_dic.Key == "SENSHEAT")
                {
                    this.SENSHEAT = Convert.ToInt32(m_dic.Value);
                }
                if (m_dic.Key == "STABILITY")
                {
                    this.STABILITY = Convert.ToInt32(m_dic.Value);
                }
                if (m_dic.Key == "USTAR")
                {
                    this.USTAR = Convert.ToInt32(m_dic.Value);
                }
                if (m_dic.Key == "WSTAR")
                {
                    this.WSTAR = Convert.ToInt32(m_dic.Value);
                }
            }
        }
    }
}
